﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using HyMaterialStatistic;
using HYView;

namespace ElectricMaterialStatistic
{
	[Transaction(TransactionMode.Manual)]
	public class CmdElectricMaterialStatistic : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			CmdViewType types = CmdViewType.FloorPlan;
			if (SwitchView.SetUsableView(types, commandData) != Autodesk.Revit.UI.Result.Succeeded)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			Document document = commandData.Application.ActiveUIDocument.Document;
			List<string> list = new List<string>();
			list.Add("材料表");
			list.Add("设备表");
			list.Add("设备材料表");
			list.Add("主要设备、图形符号表");
			Result result;
			try
			{
				ElectricRequestHandler electricRequestHandler = new ElectricRequestHandler();
				ExternalEvent exEvent = ExternalEvent.Create(electricRequestHandler);
				ElectricGridManager gridMag = new ElectricGridManager();
				DlgElectircFilter dlgFilter = new DlgElectircFilter(commandData, electricRequestHandler, exEvent);
				GridApplication.thisApp.ShowForm(commandData, electricRequestHandler, exEvent, dlgFilter, gridMag, MEP_SPECIALITY.Electric, list);
				result = Autodesk.Revit.UI.Result.Succeeded;
			}
			catch (Exception ex)
			{
				message = ex.Message;
				result = Autodesk.Revit.UI.Result.Failed;
			}
			return result;
		}
	}
}
